{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Nifty script to crop an image by supplying a binary mask. Let's assume we have a brain scan and an associated binary mask like\n",
    "<table>\n",
    "<tr>\n",
    "<td><img alt=\"Brainscan\" src=\"images/flair.png\" /></td>\n",
    "<td><img alt=\"Brainmask\" src=\"images/brainmask.png\" /></td>\n",
    "</tr>\n",
    "</table>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can crop the original image using"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Traceback (most recent call last):\n",
      "  File \"/home/loli/.local/bin/medpy_extract_sub_volume_by_example.py\", line 6, in <module>\n",
      "    exec(compile(open(__file__).read(), __file__, 'exec'))\n",
      "  File \"/home/loli/Workspace/python/medpy/bin/medpy_extract_sub_volume_by_example.py\", line 163, in <module>\n",
      "    main()    \n",
      "  File \"/home/loli/Workspace/python/medpy/bin/medpy_extract_sub_volume_by_example.py\", line 88, in main\n",
      "    (max(0, mask[2].min() - args.offset), mask[2].max() + 1 + args.offset)) # minx, maxx / miny, maxy / minz, maxz\n",
      "IndexError: tuple index out of range\n"
     ]
    },
    {
     "ename": "",
     "evalue": "1",
     "output_type": "error",
     "traceback": []
    }
   ],
   "source": [
    "medpy_extract_sub_volume_by_example.py resources/flair.nii.gz output/cropped.nii.gz resources/brainmask.nii.gz "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Bash",
   "language": "bash",
   "name": "bash"
  },
  "language_info": {
   "codemirror_mode": "shell",
   "file_extension": ".sh",
   "mimetype": "text/x-sh",
   "name": "bash"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
